package com.aaa.book_mall.dao.impl;

import com.aaa.book_mall.dao.DetailDao;
import com.aaa.book_mall.entity.Detail;
import com.aaa.book_mall.util.JDBCUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 入库详情的接口实现类
 * fileName:DetailDaoImpl
 * description:
 * author:付亚星
 * createTime:2021/1/27 16:06
 * version:1.0.0
 */
public class DetailDaoImpl implements DetailDao {


    @Override
    public int insertDetail(Detail detail) {
        String sql = "insert into t_detail values(null,?,?,?)";
        int i = JDBCUtil.update(sql, detail.getAudit_number(),detail.getBookid(),detail.getBookcount());
        return i;
    }

    @Override
    public List<Detail> queryDetail(String audit_number) {
        String sql = "select bookid,bookcount from t_detail  where audit_number=?";
        List<List> lists = JDBCUtil.queryList(sql, audit_number);
        ArrayList<Detail> Details = new ArrayList<>();
        if(lists.size()>0){
            for (List list : lists) {
                Detail Detail = new Detail((Integer)list.get(0),(Integer)list.get(1));
                Details.add(Detail);
            }
            return Details;
        }
        return null;
    }

    @Override
    public List<Map<String, Object>> showInfoDetail(String audit_number) {
       String sql = "SELECT td.audit_number,tb.bookname,tb.price,td.bookcount,tb.count,tb.publisher from t_detail td inner JOIN t_book tb on tb.bookid=td.bookid where td.bookid in (select bookid from t_detail where audit_number=?) and td.audit_number=?";
        List<Map<String, Object>> maps = JDBCUtil.queryListMap(sql, audit_number, audit_number);
        return maps;
    }
}
